package com.migration.model.migration.scripts;

import com.migration.model.migration.AbstractMigrationScript;

/**
 * 设备-操作表(risk_device_operation)迁移脚本
 */
public class A011_RiskDeviceOperationMigrationScript extends AbstractMigrationScript {

    /**
     * 构造函数，初始化迁移配置
     */
    public A011_RiskDeviceOperationMigrationScript() {
        super(
            "risk_device_operation",
            "设备-操作数据迁移",
            "ra_node_relation",
            "risk_device_operation",
            11
        );
    }

    /**
     * 生成迁移数据的SQL
     *
     * @return 迁移数据的SQL
     */
    @Override
    protected String generateMigrationSql() {
        return "INSERT INTO risk_device_operation (\n" +
               "id,\n" +
               "department_id,\n" +
               "device_id,\n" +
               "operation_id,\n" +
               "cause_quantity,\n" +
               "consequence_quantity\n" +
               ")\n" +
               "SELECT\n" +
               "nr.id,\n" +
               "n.tenant_id AS department_id,\n" +
               "nr.node_id AS device_id,\n" +
               "nr.linked_id AS operation_id,\n" +
               "0,\n" +
               "0\n" +
               "FROM risk_lunnan_test.ra_node_relation nr\n" +
               "LEFT JOIN risk_lunnan_test.ra_node n ON nr.node_id = n.id AND n.is_del = 0\n" +
               "where nr.linked_type = 4\n" +
               "GROUP BY nr.id;";
    }

    /**
     * 获取源数据SQL
     *
     * @return 源数据查询SQL
     */
    public String getSourceSql() {
        return "SELECT\n" +
               "nr.id,\n" +
               "n.tenant_id,\n" +
               "nr.node_id,\n" +
               "nr.linked_id\n" +
               "FROM risk_lunnan_test.ra_node_relation nr\n" +
               "LEFT JOIN risk_lunnan_test.ra_node n ON nr.node_id = n.id AND n.is_del = 0\n" +
               "where nr.linked_type = 4\n" +
               "GROUP BY nr.id;";
    }

    /**
     * 获取目标数据SQL模板
     *
     * @return 目标数据SQL模板
     */
    public String getTargetSqlTemplate() {
        return "INSERT INTO risk_device_operation (\n" +
               "id,\n" +
               "department_id,\n" +
               "device_id,\n" +
               "operation_id,\n" +
               "cause_quantity,\n" +
               "consequence_quantity\n" +
               ")";
    }
}
